<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>静态表格</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
    <script src="__STATIC__/js/jquery-1.8.3.min.js"></script>
    <script src="__STATIC__/js/common.js"></script>

</head>
<body>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>组件</cite></a>
        <a><cite>静态表格</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    文章列表
                </div>

                <div class="layui-card-body">
                    <div class="layui-col-xs7">
                        <button class="layui-btn layui-btn-sm" onclick="goUrl('{:url('add')}')">
                            <i class="layui-icon">&#xe654;</i>添加文章
                        </button>
                        <button class="layui-btn layui-btn-danger layui-btn-sm" onclick="delAll()">
                            <i class="layui-icon">&#xe640;</i>批量删除
                        </button>
                        <script>

                            function delAll() {
                                let idArr = [];

                                $('.id-checkbox:checked').each(function () {
                                    idArr.push($(this).data('id'))
                                })

                                if (idArr.length > 0) {
                                    let id = idArr.join(',');
                                    $.ajax({
                                        url: '{:url("del")}',
                                        type: 'get',
                                        // 设置的是请求参数
                                        data: {id},
                                        // 用于设置响应体的类型 注意 跟 data 参数没关系！！！
                                        dataType: 'json',
                                        success: function (res) {
                                            layer.msg(res.msg);
                                            setTimeout(function () {
                                                location.reload()
                                            }, 500)
                                        }
                                    })
                                }
                            }

                        </script>
                    </div>

                    <div class="layui-col-sm5">
                        <div class="layui-form-item">
                            <form class="form-inline" method="post" action="{:url('index')}">
                                <div class="layui-input-inline" >
                                    <input type="text" name="keyword" value="{$keyword}" placeholder="请输入关键字"  lay-verify="title" autocomplete="off"  class="layui-input">
                                </div>
                                <input type="hidden" name="pid" value="{$pid}">
                                <button type="submit" class="layui-btn" >查询</button>
                            </form>
                        </div>
                    </div>

                    <table class="layui-table">
                        <colgroup>
                            <col width="150">
                            <col width="150">
                            <col width="200">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th width="1%">
                                <input type="checkbox" name="acc_roleid[]" value="" class="all" lay-skin="primary">
                            </th>
                            <th width="5%">编号</th>
                            <th width="37%">文章名称</th>
                            <th width="12%">文章封面图</th>
                            <th width="12%">最后更新时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="vo"}
                        <tr>
                            <td>
                                <input type="checkbox" data-id="{$vo['id']}" class="id-checkbox" value="" lay-skin="primary">
                            </td>
                            <td>{$vo.id}</td>
                            <td>{$vo.article_name}</td>
                            <td>
                                {if $vo['image'] neq ""}
                                <img src="{$vo['image']}" width="50" height="50">
                                {else/}
                                暂无图片
                                {/if}
                            </td>
                            <td>{$vo.update_time|date="Y-m-d H:i:s"}</td>

                            <td>
                                {if $vo['status'] eq 1}
                                <font color="#009900">已审核</font>
                                {else/}
                                <font color="#999999">未审核</font>
                                {/if}
                            </td>
                            <td>
                                <a href="{:Url('edit',array('id' => $vo['id']))}" class="layui-btn  layui-btn-sm"><i class="layui-icon">&#xe642;</i>编辑</a>
                                <a onclick="article_del(this)"  href="javascript:;" url="{:url('cate_del')}?art_id={$vo['id']}" class="layui-btn layui-btn-danger layui-btn-sm"><i class="layui-icon">&#xe640;</i>删除</a>

                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                    {$page|raw}
                </div>
            </div>
        </div>


    </div>
</div>

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script src="__STATIC__/js/layer_hplus.js"></script>
<script src="__STATIC__/common.js"></script>
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index']);

    function article_del(obj){
        var url = $(obj).attr('url');
        //alert(url);
        layer.confirm('确认要删除吗？',function(index){

            $.ajax({
                type: 'POST',
                url: url,
                data: {'id':url},
                dataType: 'json',
                success: function(data){
                    if(data.status==200){
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.href = data.url;
                        });
                    }
                },
            });
        });
    }

    $('.all').click(function() {
        if($(this).is(':checked')) {
            $(':checkbox').prop("checked", true);
        } else {
            $(':checkbox').prop("checked", false);
        }
    });


</script>
</body>
</html>